package com.itheima.tlias84.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.tlias84.dto.SelectAllClazzDTO;
import com.itheima.tlias84.dto.SelectClazzDTO;
import com.itheima.tlias84.dto.SelectClazzDetailDTO;
import com.itheima.tlias84.mapper.ClazzMapper;
import com.itheima.tlias84.po.InsertClazzParam;
import com.itheima.tlias84.po.SelectClazzPageParam;
import com.itheima.tlias84.po.UpdateClazzParam;
import com.itheima.tlias84.service.ClazzService;
import com.itheima.tlias84.utils.ResultUtil;
import com.itheima.tlias84.vo.PageVO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class ClazzServiceImpl implements ClazzService {
    @Resource
    ClazzMapper clazzMapper;
    //分页查询
    @Override
    public ResultUtil selectClazzByPage(SelectClazzPageParam param) {
        Page<Object> page = PageHelper.startPage(param.getPage(), param.getPageSize());
        List<SelectClazzDTO> dtos = clazzMapper.selectClazzByPage(param);
        PageVO<SelectClazzDTO> pageVO = new PageVO<>();
        pageVO.setTotal(page.getTotal());
        pageVO.setRows(dtos);
        return ResultUtil.success(pageVO);
    }
    //修改
    @Override
    public int updateClazz(UpdateClazzParam param) {

        return clazzMapper.updateClazz(param);
    }

    @Override
    public SelectClazzDetailDTO selectClazzById(Integer id) {
        SelectClazzDetailDTO dto = clazzMapper.selectClazzById(id);
        return dto;
    }

    @Override
    public int deleteClazzById(Integer id) {
        int flag = clazzMapper.deleteClazzById(id);
        return flag;
    }

    @Override
    public int insertClazz(InsertClazzParam param) {
        int flag = clazzMapper.insertClazz(param);
        return flag;
    }

    @Override
    public List<SelectAllClazzDTO> selectAllClazz() {
        List<SelectAllClazzDTO> dtos = clazzMapper.selectAllClazz();
        return dtos;
    }
}
